<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script type="text/javascript">


    var type = 'add'; // sub
    var n1 = 12;
    var n2 = 34;
    var rs;


    switch (type) {

        case 'add':
            console.log('add执行了');
            console.log('add执行了');
            console.log('add执行了');
            rs = n1 + n2;

            /*在case后面如果不加上 break 即使后面的case不满足条件，程序继续向下执行，一般都加 break*/
            // break;

        case 'sub':
            console.log('sub 执行了');
            rs = n1 - n2;
            break;

        default:
            console.log('default 执行了');
            console.log('default 执行了');
            console.log('default 执行了');
            console.log('default 执行了');
            rs = n1 * n2;
    }

    console.log(rs);


</script>

</html>
